package unwdmi.main;
import java.io.IOException;
import java.net.ServerSocket;
import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.mongodb.DB;
import com.mongodb.MongoClient;

import unwdmi.connector.ClientConnector;
import unwdmi.listener.ClientListener;
import unwdmi.listener.StationListener;
import unwdmi.db.*;
import unwdmi.dto.*;

/**
 * Main program to start
 * @author Stephan E G Veenstra
 *
 */
public class Main {
	
	
	public static MongoDB MONGO_INSTANCE;
	
	public static final int STATION_PORT = 7789;
	public static final int CLIENT_PORT = 7790;
	
	public static final int STATION_CONNECTION_LIMIT = 800;
	
	private ExecutorService executor;
	private ServerSocket serverStationSocket;
	private ServerSocket serverClientSocket;
	
	private Main(){
		try {
			
			
			Main.MONGO_INSTANCE = new MongoDB();
			
			serverStationSocket = new ServerSocket(STATION_PORT);
			serverClientSocket = new ServerSocket(CLIENT_PORT);
			executor = Executors.newFixedThreadPool(3);
			
			// Add A StationListener
			executor.execute(new StationListener(serverStationSocket, STATION_CONNECTION_LIMIT));
			// Add a ClientListener
			executor.execute(new ClientListener(serverClientSocket));
			
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			executor.shutdown();
		}
	}
	
	public static void main(String[] args) {
		new Main();
	}

}
